home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
Communications
/
Networks
/
MailCheck 0.9x
/
cdev src
/
cdev runner.c
next >
Wrap
C/C++ Source or Header
|
1991-06-22
|
4KB
|
211 lines
/*
* cdev runner.c
*
* Copyright (c) 1991 Symantec Corporation. All rights reserved.
*
*/
static char CDEV[] = "\p*sample*";
static MenuHandle appleMenu; /* Apple menu */
#define hiword(x) (((short *) &(x))[0])
#define loword(x) (((short *) &(x))[1])
extern short Keys : 0x17A;
static __A5(void);
static doEvent(EventRecord *event);
static doMenu(long choice);
main()
{
short i, refnum;
Handle r;
extern pascal long myMain();
MenuHandle menu;
EventRecord event;
SysEnvRec theWorld;
register struct jump { short jump; long addr; } *p;
/* initialize */
MaxApplZone();
for (i = 0; i < 10; i++)
MoreMasters();
InitGraf(&thePort);
InitCursor();
InitFonts();
InitWindows();
TEInit();
InitDialogs(0);
InitMenus();
FlushEvents(everyEvent, 0);
/* look up cdev */
if (SysEnvirons(1, &theWorld))
return;
if (SetVol(0, theWorld.sysVRefNum))
return;
if ((refnum = OpenResFile(CDEV)) < 0)
return;
if ((r = Get1Resource('cdev', -4064)) == 0)
return;
p = (struct jump *) (*r + 16);
p->jump = 0x4EF9;
p->addr = (long) myMain;
ChangedResource(r);
CloseResFile(refnum);
/* remember CurrentA5 */
__A5();
asm {
move.l a5,(a0)
}
/* build apple menu */
InsertMenu(appleMenu = NewMenu(1, "\p\024"), 0);
AddResMenu(appleMenu, 'DRVR');
/* build remaining menus */
InsertMenu(menu = NewMenu(2, "\pFile"), 0);
AppendMenu(menu, "\pOpen/O;Close;Quit/Q");
InsertMenu(menu = NewMenu(3, "\pEdit"), 0);
AppendMenu(menu, "\pUndo/Z;(-;Cut/X;Copy/C;Paste/V;Clear");
DrawMenuBar();
/* process events */
for (;;) {
HiliteMenu(0);
SystemTask();
SEvtEnb = false;
if (GetNextEvent(everyEvent, &event)) {
if (!SystemEvent(&event))
doEvent(&event);
}
else if (event.what == nullEvent) {
if (FrontWindow() == 0)
InitCursor();
}
}
}
/*
* doEvent - handle event
*
*/
static
doEvent(EventRecord *event)
{
short part;
WindowPeek wp;
static Point where = { 0x0064, 0x0064 };
switch (event->what) {
case diskEvt:
if (hiword(event->message)) {
InitCursor();
DIBadMount(where, event->message);
}
break;
case mouseDown:
switch (part = FindWindow(event->where, &wp)) {
case inMenuBar:
InitCursor();
doMenu(MenuSelect(event->where));
break;
case inSysWindow:
SystemClick(event, wp);
break;
}
break;
case keyDown:
if (event->modifiers & cmdKey)
doMenu(MenuKey(loword(event->message)));
break;
}
}
/*
* doMenu - process menu selection
*
*/
static
doMenu(long choice)
{
short i = loword(choice);
Str255 buf;
WindowPeek wp;
switch (hiword(choice)) {
case 1: /* Apple */
GetItem(appleMenu, i, buf);
OpenDeskAcc(buf);
break;
case 2: /* File */
switch (i) {
case 1: /* Open */
while (Keys)
;
Keys = 4;
OpenDeskAcc("\p\0Control Panel");
Keys = 0;
break;
case 2: /* Close */
if (wp = (WindowPeek) FrontWindow())
CloseDeskAcc(wp->windowKind);
break;
case 3: /* Quit */
ExitToShell();
}
break;
case 3: /* Edit */
SystemEdit(i - 1);
break;
}
}
static
__A5(void)
{
asm {
bsr.s @1
dc.l 0
@1 movea.l (sp)+,a0
}
}
static pascal long
myMain(short x0, short x1, short x2, short x3, long x4, long x5, long x6)
{
extern pascal long _main(short, short, short, short, long, long, long);
__A5();
asm {
move.l (a0),d0
cmp.l CurrentA5,d0
bne.s @done
suba.l a0,a0
move.l a5,-(sp)
movea.l d0,a5
}
x5 = _main(x0, x1, x2, x3, x4, x5, x6);
asm {
movea.l (sp)+,a5
}
done:
return(x5);
}